using System;
using System.Collections;

namespace CSharp_1209.Hospital
{
    public class DoctorTable
    {
        public Hashtable objDoctorDetails = new Hashtable();

        public void AcceptDetails()
        {
            try
            {
                char choice = 'Y';
                do
                {
                    Console.Write("Enter the doctor's name : ");
                    string name = Console.ReadLine();

                    Console.Write("Enter the address : ");
                    string address = Console.ReadLine();

                    objDoctorDetails.Add(name, address);
                    Console.Write("Do you want to add more records? [Y/N] : ");

                    choice = Convert.ToChar(Console.ReadLine());
                } while (choice == 'Y' || choice == 'y');
            }
            catch (Exception objEx)
            {
                Console.WriteLine("Error : {0}", objEx.Message);
            }
        }

        public void DisplayDetails()
        {
            ICollection objCollection = objDoctorDetails.Keys;

            Console.WriteLine("\nDetails of doctors :");
            Console.WriteLine("Doctor's Name \t Address");
            Console.WriteLine("------------- \t -------");

            foreach (string details in objCollection)
            {
                Console.WriteLine(details + "\t\t " + objDoctorDetails[details]);
            }

            Console.WriteLine("Total number of doctors : " + objDoctorDetails.Count);
        }

        public bool Remove()
        {
            Console.Write("Enter the name of the doctor : ");
            string choice = Console.ReadLine();

            if (objDoctorDetails.ContainsKey(choice))
            {
                objDoctorDetails.Remove(choice);
                return true;
            }
            return false;
        }

        public void Search()
        {
            Console.Write("Enter the name of the doctor : ");
            string choice = Console.ReadLine();
            if (choice != "")
            {
                if (objDoctorDetails.ContainsKey(choice))
                {
                    Console.WriteLine("Record Found!");
                    Console.WriteLine("Doctor's Name : {0}", choice);
                    // Displaying address of the doctor using the Item property
                    Console.WriteLine("Address : {0}", objDoctorDetails[choice]);
                }
                else
                    Console.WriteLine("Record Not Found!");
            }
            else
            {
                Console.WriteLine("Invalid Input!");
            }
        }
    }
}
